home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / lang / c--c0202 / random.h-- < prev    next >
Encoding:
Text File  |  1993-05-19  |  1.1 KB  |  60 lines

  1. /*
  2.     SPHINX Programming (C) 1993.
  3.     TITLE:  RANDOM.H--
  4.     DESCRIPTION:  This file contains a collection of procedures for
  5.                   generating pseudo random integer values.
  6.     LAST MODIFIED:  19 May 1993
  7.     PROCEDURES DEFINED IN THIS FILE:
  8.         : int  RAND()
  9.         : void RANDOMIZE()
  10.         : void srand(seedlow,seedhigh)
  11. */
  12.  
  13.  
  14. word randseed[2]={0,0};  // random number generator seed
  15.  
  16.  
  17. : int RAND ()
  18. {
  19. BX = randseed[2];
  20. CX = randseed[0];
  21. AL = BH;
  22. BH = BL;
  23. BL = CH;
  24. CH = CL;
  25. $XOR CL,CL
  26. $RCR AL,1
  27. $RCR BX,1
  28. $RCR CX,1
  29. CX += randseed[0];
  30. $ADC BX,randseed[2]
  31. CX += 0x62E9;
  32. $ADC BX,0x3619
  33. randseed[2] = BX;
  34. randseed[0] = CX;
  35. AX = BX;
  36. }
  37. /* RETURNS:  AX = random value in the range of 0x0000 to 0xFFFF
  38.              BX,CX = undefined
  39. */
  40.  
  41.  
  42. : void RANDOMIZE ()
  43. {ES = 0x0000;
  44. randseed[0] = ESWORD[0x46C];
  45. randseed[2] = ESWORD[0x46E];
  46. }
  47. /* RETURNS:  AX = undefined
  48.              ES = 0x0000
  49. */
  50.  
  51.  
  52. : void srand (word seedlow, seedhigh)
  53. {randseed[0] = seedlow;
  54. randseed[2] = seedhigh;
  55. }
  56. /* RETURNS:  AX = seedhigh
  57. */
  58.  
  59.  
  60. /* end of RANDOM.H-- */